import {TARGET_TYPE_ENUM} from '~/utils/const';

/**
 * 该工具包主要用来从数据库读取特殊路径（衡量指标不同的路径）并定义一些公用方法
 * @param targetType{Number} - 性能指标类型. 比如1:首屏时间,9:FSP,10:FI
 * @param bizTypeName{String} - 业务线,目前只有'高途'
 * @param bizName{String} - 应用名称
 * @param path{String} -路径
 * @param order{Number} -路径顺序，（方便扩展）
 * @param startTime{String} - 开始时间yyyy-MM-ddHH:mm:ss,(方便扩展)
 * @param endTime{String} - 结束时间yyyy-MM-ddHH:mm:ss，（方便扩展）
 * @param timeType{Number} - 时间标签. 比如1: 一天,10:10分钟（方便扩展）
 */
export const PATH = [
    {
        targetType: 9,
        bizTypeName: '高途',
        bizName: 'gt-m',
        path: '/',
        order: 1
    },
    {
        targetType: 9,
        bizTypeName: '高途',
        bizName: 'gt-m',
        path: '/learn/',
        order: 2
    },
    {
        targetType: 9,
        bizTypeName: '高途',
        bizName: 'gt-m',
        path: '/study',
        order: 3
    },
    {
        targetType: 10,
        bizTypeName: '高途',
        bizName: 'gt-activity-end',
        path: '/Criss/lijian',
        order: 4
    },
    {
        targetType: 10,
        bizTypeName: '高途',
        bizName: 'gt-activity-end',
        path: '/Criss/lijian02',
        order: 5
    },
    {
        targetType: 10,
        bizTypeName: '高途',
        bizName: 'gt-activity-end',
        path: '/Criss/lijian03',
        order: 6
    },
    {
        targetType: 10,
        bizTypeName: '高途',
        bizName: 'gt-itive-student',
        path: '/newExercise/pc',
        order: 7
    },
    {
        targetType: 10,
        bizTypeName: '高途',
        bizName: 'gt-itive-student',
        path: '/newExercise/android',
        order: 8
    },
    {
        targetType: 10,
        bizTypeName: '高途',
        bizName: 'gt-itive-student',
        path: '/newExercise/ios',
        order: 9
    },
    {
        targetType: 10,
        bizTypeName: '高途',
        bizName: 'gt-itive-student',
        path: '/newBeforeExercise/pc',
        order: 10
    },
    {
        targetType: 10,
        bizTypeName: '高途',
        bizName: 'gt-itive-student',
        path: '/newBeforeExercise/android',
        order: 11
    },
    {
        targetType: 10,
        bizTypeName: '高途',
        bizName: 'gt-itive-student',
        path: '/newBeforeExercise/ios',
        order: 12
    },
    {
        targetType: 10,
        bizTypeName: '高途',
        bizName: 'gt-cw-cocos',
        path: '/grade_spring20/android',
        order: 13
    },
    {
        targetType: 10,
        bizTypeName: '高途',
        bizName: 'gt-cw-cocos',
        path: '/grade_spring20/ios',
        order: 14
    },
    {
        targetType: 10,
        bizTypeName: '高途',
        bizName: 'gt-cw-cocos',
        path: '/grade_spring20/pc',
        order: 15
    },
    {
        targetType: 10,
        bizTypeName: '高途',
        bizName: 'gt-cw-cocostpl',
        path: '/grade_template19/android',
        order: 19
    },
    {
        targetType: 10,
        bizTypeName: '高途',
        bizName: 'gt-cw-cocostpl',
        path: '/grade_template19/ios',
        order: 20
    },
    {
        targetType: 10,
        bizTypeName: '高途',
        bizName: 'gt-cw-cocostpl',
        path: '/grade_template19/pc',
        order: 21
    },
    {
        targetType: 10,
        bizTypeName: '高途',
        bizName: 'gt-cw-pixi',
        path: '/courseware-pixi/android',
        order: 22
    },
    {
        targetType: 10,
        bizTypeName: '高途',
        bizName: 'gt-cw-pixi',
        path: '/courseware-pixi/ios',
        order: 23
    },
    {
        targetType: 10,
        bizTypeName: '高途',
        bizName: 'gt-cw-pixi',
        path: '/courseware-pixi/pc',
        order: 24
    },
    {
        targetType: 10,
        bizTypeName: '高途',
        bizName: 'gt-cw-h5',
        path: '/courseware-h5/',
        order: 25
    },
    {
        targetType: 9,
        bizTypeName: '高途',
        bizName: 'gt-pc',
        path: '/learn',
        order: 26
    },
    {
        targetType: 10,
        bizTypeName: '高途',
        bizName: 'gt-activity-end-ssr',
        path: '/activity/criss/groupon',
        order: 27
    }
];

// 定义找出路径是否属于特殊路径的方法,是的话则返回FSP或FI，否则返回false
export const isPathSpecial = (application, path) => {
    const index = PATH.findIndex(item => item.bizName === application && item.path === path);
    if (index !== -1) {
        return PATH[index].targetType;
    }
    return TARGET_TYPE_ENUM.TTFP;
};

// 定义获取应用列表的方法
export const findApplicationList = () => [...new Set(PATH.map(item => item.bizName))];

// 通过应用名称过滤PATH
export const filterPathByApplication = (paths, bizName) => {
    if (bizName === 'all') {
        return paths;
    }
    return paths.filter(item => item.bizName === bizName);
};
